import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { ShoppingCartData ,DocsList} from '@/typings'
export const useOrderListStore = defineStore('orderList', () => {
    const toBePaidList = ref<Array<ShoppingCartData>>([])
    const collectionList =ref<Array<DocsList>>([])
    function addBePaidList(list: ShoppingCartData) {

        toBePaidList.value.unshift(list)
        console.log(toBePaidList.value);

    }

    function setBePaidList(id: number, expiredNotType: number) {
        toBePaidList.value.map(item => {
            if (item.id == id) {
                item.expiredNotType = expiredNotType
                console.log(item.expiredNotType);
                return
            }
        })
    }

    function delTobeoaid(id: number) {
        toBePaidList.value = toBePaidList.value.filter(t => t.id != id)
    }

    function addCollection(list:DocsList){
        collectionList.value=collectionList.value.filter(t=>t.tradeItemId!=list.tradeItemId)
        collectionList.value.unshift(list)
        localStorage.loaclCollectionList = JSON.stringify( collectionList.value)
        console.log( collectionList.value);
        
    }
    function delCollection(id:string) {
        collectionList.value = collectionList.value.filter(t=>t.tradeItemId!=id)
        localStorage.loaclCollectionList = JSON.stringify( collectionList.value)
        console.log( collectionList.value);

    }

    return { toBePaidList,collectionList, addBePaidList, setBePaidList, delTobeoaid,addCollection,delCollection }
})
